package com.xneure.database;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.JdbcType;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.xneure.utils.bean.GUID;
@Component
@Scope("prototype")
public class GUIDHandler extends MyBatisTypeHandler<GUID> {

	@Override
	public void setNonNullParameter(PreparedStatement ps,int index,GUID parameter,JdbcType jdbcType) throws SQLException{
		ps.setString(index, String.valueOf(parameter));
	}

	@Override
	public GUID getNullableResult(ResultSet rs,String columnName) throws SQLException{
		return GUID.valueOf(rs.getString(columnName));
	}

	@Override
	public GUID getNullableResult(ResultSet rs,int columnIndex) throws SQLException{
		return GUID.valueOf(rs.getString(columnIndex));
	}

	@Override
	public GUID getNullableResult(CallableStatement cs,int columnIndex) throws SQLException{
		return GUID.valueOf(cs.getString(columnIndex));
	}

	@Override
	public Class<?>[] supportType(){
		return new Class[] {GUID.class};
	}

	@Override
	public JdbcType[] jdbcType(){
		return new JdbcType[] {JdbcType.VARCHAR,JdbcType.NVARCHAR,JdbcType.CHAR};
	}
}